local legos = LibStub("LegoBlock-Beta1")
Legos = DongleStub("Dongle-1.0"):New("Legos", {})
local Legos = Legos
local legoblocks = {}

local bigString = "This is a realy really really long string for BigBlocks"
--local ClickTip = DongleStub("ClickTip-1.0")

local profile

function Legos:Initialize()
	self.defaults = {
		profile = {
			legos = {},
			alarms = {},
		},
	}
	--self:SetIcon("Interface\\Addons\\LegoBlock\\tests\\Legos.tga")
	self:CreateSlashCommands()
end

function Legos:Enable()
	self.db = self:InitializeDB("LegosDB", self.defaults)
	profile = self.db.profile
	for k, v in pairs(profile.legos) do
		table.insert(legoblocks, legos:New("ML"..k,"NewBlock"..k,nil,v))
		legoblocks[#legoblocks]:ShowText()
		legoblocks[#legoblocks]:SetBackdropColor(0, 0, 0, 1.0)
	end
end

function Legos:Disable()
end

function Legos:CreateSlashCommands()
	local cmd = self:InitializeSlashCommand("Legos slash commands", "Legos", "Legos", "leg", "lb")
	local function reset()
		self.db:ResetDB()
	end
	local function mb(count)
		for i=1,count do
			table.insert(self.db.profile.legos,{})
			table.insert(legoblocks,legos:New("ML"..#self.db.profile.legos,"NewBlock"..#self.db.profile.legos, nil, self.db.profile.legos[#self.db.profile.legos]))
			legoblocks[#legoblocks]:ShowText()
		end
	end
	local function nb()
		table.insert(self.db.profile.legos,{})
		table.insert(legoblocks,legos:New("ML"..#self.db.profile.legos,"NewBlock"..#self.db.profile.legos, nil, self.db.profile.legos[#self.db.profile.legos]))
		legoblocks[#legoblocks]:ShowText()
	end
	local function bb()
		table.insert(self.db.profile.legos,{})
		table.insert(legoblocks,legos:New("ML"..#self.db.profile.legos,"BigBlock"..#self.db.profile.legos..bigString, nil, self.db.profile.legos[#self.db.profile.legos]))
		legoblocks[#legoblocks]:ShowTex()
	end
	cmd:RegisterSlashHandler("reset - Show configuration frame", "^reset$", reset)
	cmd:RegisterSlashHandler("nb - creat a new block", "^nb$", nb)
	cmd:RegisterSlashHandler("bb - create a big block", "^bb$", bb)
	cmd:RegisterSlashHandler("mb - create many new blocks", "^mb (%d+)$", mb)
end
